package operation;

import Book.Book;
import Book.BookList;

import java.util.Scanner;

public class DelOperation implements Ioperation{
    public void work(BookList bookList) {
        System.out.println("删除图书");
        Scanner scanner = new Scanner(System.in);
        System.out.println("请输入你要删除的图书");
        String name = scanner.nextLine();
        int current = bookList.getUseSize();
        int i = 0;
int index = -1;
        for (; i < current; i++) {
            Book tem = bookList.getBook(i);
            if (tem.getName().equals(name)) {
                index = i;
                break;
            }
        }
        if (i >= current) {
            System.out.println("没有你要找的书");
            return;
        }
        for (int j = index; j < current - 1; j++) {
            Book book = bookList.getBook(j + 1);
            bookList.setBooks(book, j);
        }
        bookList.setBooks(null,current-1);
        bookList.setUseSize(current-1);
        System.out.println("成功删除");
    }
}

